package com.xsky.logic;

import java.util.List;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.basic.DateConverter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.xsky.converter.XStreamClobConverter;
import com.xsky.database.dao.impl.BaseEntityDaoImpl;
import com.xsky.operation.vo.TabConfigure;

public class ConfigureLogic 
{
	public String genSubByParentId(String parentId)//获取某一类
	{
		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		List rootList = baseDao.findByHql("from TabConfigure model where model.parentId='"+parentId+"' order by code asc");
		String result = "<data>";
		XStream xs = new XStream(new DomDriver());
		String defaultFormat = "yyyy-MM";
		String[] acceptableFormat = {"yyyy-MM"};
		xs.registerConverter(new DateConverter(defaultFormat,acceptableFormat));
		xs.registerConverter(new XStreamClobConverter());
		xs.alias("item", TabConfigure.class);
		for (int i =0; i<rootList.size(); i++)
		{
			TabConfigure entity = (TabConfigure)rootList.get(i);
			result+=xs.toXML(entity);
		}
		return result;
	}
	public String genSubByParentId(String parentId, String outLinkId)//获取某一类下的所有的子类
	{
		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		List rootList = baseDao.findByHql("from TabConfigure model where model.parentId='"+parentId+"' and model.outLinkId='"+outLinkId+"'order by code asc");
		String result = "<data>";
		XStream xs = new XStream(new DomDriver());
		String defaultFormat = "yyyy-MM";
		String[] acceptableFormat = {"yyyy-MM"};
		xs.registerConverter(new DateConverter(defaultFormat,acceptableFormat));
		xs.registerConverter(new XStreamClobConverter());
		xs.alias("item", TabConfigure.class);
		for (int i =0; i<rootList.size(); i++)
		{
			TabConfigure entity = (TabConfigure)rootList.get(i);
			result+=xs.toXML(entity);
		}
		return result;
	}
	public String judgeIsLeafe(String id)
	{
		BaseEntityDaoImpl baseDao = new BaseEntityDaoImpl();
		TabConfigure model = (TabConfigure)baseDao.findByPrimaryKey("TabConfigure", "id", id);
		if(model!=null)
		{
			return "是";
		}
		else
		{
			return "否";
		}
	}
}
